
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Portatil Siag
 */
public class PhotosCache {

    private static PhotosCache INSTANCE = null;
    private Hashtable<String, Hashtable<Integer, Photograph>> cache =
            new Hashtable<String, Hashtable<Integer, Photograph>>();

    private PhotosCache() {
    }

    public static PhotosCache getDefault() {
        if (INSTANCE == null) {
            INSTANCE = new PhotosCache();
        }
        return INSTANCE;
    }

    public String put(Photograph p) {
        String id = p.get_album();

        Hashtable<Integer, Photograph> temp = cache.get(p.get_album());
        if (temp == null) {
            temp = new Hashtable<Integer, Photograph>();
        }
        temp.put(p.get_id(), p);
        cache.put(id, temp);

        return id;
    }

    public Hashtable<Integer, Photograph> getPhotosByAlbum(String album) {
        return cache.get(album);
    }

    public Vector<Photograph> getPhotosByAlbumVector(String s) {
        Hashtable<Integer, Photograph> album = PhotosCache.getDefault().getPhotosByAlbum(s);
        Enumeration<Integer> index = album.keys();
        Vector<Photograph> vec = new Vector<Photograph>();
        Integer i = 0;
        
        while (index.hasMoreElements()) {
            i = index.nextElement();
            Photograph p = album.get(i);
            vec.add(p);
        }

        return vec;
    }
}
